import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Confirm from 'vux/src/components/confirm/index.vue'

export default {
  name: 'mine',
  components: {Confirm},
  data () {
    return {
      height: '',
      openId: '',
      siteId: '',
      studentId: '',
      wxAvatar: '',
      pageNo: 1,
      total: '0',
      content: [],
      show: false,
      tishi: '确定退出登录?',
      iflogined: false
    }
  },
  mounted () {
    var _this = this
    _this.height = document.body.clientHeight + 'px'
    _this.studentId = window.sessionStorage.getItem('studentId')
    if (_this.studentId == '-1') {
      _this.tishi = '您目前尚未登录，是否进行登录？'
      _this.iflogined = false
      _this.show = true
    } else {
      _this.iflogined = true
      _this.openId = window.sessionStorage.getItem('openId')
      _this.siteId = window.sessionStorage.getItem('siteId')
      _this.wxAvatar = window.sessionStorage.getItem('wxAvatar')
      http.post(CONSTANT.STUDENTVIEW, {
        siteId: _this.siteId,
        studentId: _this.studentId
      }, (res) => {
        _this.content = res
      })
      http.post(CONSTANT.NOTICELIST, {
        siteId: _this.siteId,
        studentId: _this.studentId,
        pageNo: _this.pageNo
      }, (res) => {
        console.log(res)
        _this.total = res.total
      })
    }
  },
  methods: {
    goSomePage (witch) {
      var _this = this
      if (_this.iflogined == false) {
        _this.show = true
      } else {
        if (witch == 'per') {
          _this.$router.push({path: '/personalInformation'})
        } else if (witch == 'class') {
          _this.$router.push({path: '/myClass'})
        } else if (witch == 'notice') {
          _this.$router.push({path: '/notice'})
        }
      }
    },
    showconfirm () {
      var _this = this
      _this.show = true
    },
    onCancel () {
    // 取消按钮
      var _this = this
      _this.show = false
    },
    onConfirm () {
      // 确定按钮
      var _this = this
      if (_this.tishi == '确定退出登录?') {
        http.post(CONSTANT.LOGOUT, {openId: _this.openId}, (res) => {
          console.log(res)
          window.sessionStorage.setItem('studentId', '-1')
        })
      }
      _this.$router.push({path: '/login'})
    },
    goQuery() {
      this.$router.push({path: '/query'})
    }
  }
}
